package reflect;

import reflect.annotations.AutoRunClass;

import java.io.File;
import java.lang.reflect.Field;
import java.net.URISyntaxException;

public class Test8 {
    public static void main(String[] args) throws URISyntaxException, InstantiationException, IllegalAccessException, ClassNotFoundException {
        Class c=Test8.class;
        String pack = Test8.class.getPackage().getName();
        File dir=new File(c.getResource(".").toURI());
        File[] subs=dir.listFiles(f->f.getName().endsWith(".class"));
        for (File sud:subs){
            String fileName=sud.getName();
            String className = fileName.replace(".class","");
            Class<?> cls = Class.forName(pack + "." + className);
            if(cls.isAnnotationPresent(AutoRunClass.class)){
                System.out.println("实例化:"+className);
                Object obj = cls.newInstance();
                System.out.println(obj);
            }
        }
    }
}
